package com.ny.demo02;
import java.util.Scanner;
public class Test01 {

        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);

            // 方式一：调用无参构造函数，通过 set 方法赋值
            System.out.println("请输入职工信息（使用无参构造函数）：");

            System.out.print("请输入姓名：");
            String name1 = scanner.nextLine();

            System.out.print("请输入年龄：");
            int age1 = scanner.nextInt();
            scanner.nextLine(); // 清除换行符

            System.out.print("请输入部门：");
            String department1 = scanner.nextLine();

            Employee employee1 = new Employee();
            employee1.setName(name1);
            employee1.setAge(age1);
            employee1.setDepartment(department1);
            employee1.displayInfo();

            // 方式二：调用有参构造函数
            System.out.println("\n请输入职工信息（使用有参构造函数）：");

            System.out.print("请输入姓名：");
            String name2 = scanner.nextLine();

            System.out.print("请输入年龄：");
            int age2 = scanner.nextInt();
            scanner.nextLine(); // 清除换行符

            System.out.print("请输入部门：");
            String department2 = scanner.nextLine();

            Employee employee2 = new Employee(name2, age2, department2);
            employee2.displayInfo();

            scanner.close();
        }


}
